using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 改变实体阻挡是否激活
    /// 参数：1：tag(填0表示自己)，2：是否激活（0不激活，1激活）
    /// </summary>
    public class ExecSetObstacleActivation : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamSetObstacleActivation;
            var entities = ListPool<LevelEntity>.Get();
            if (!LgLevelEntityUtil.GetEntitiesByDynCfgKeys(region, triggerEntity, config.tagOrMcid, entities))
            {
                ListPool<LevelEntity>.Put(entities);
                return;
            }
            bool isObstacleActive = config.isObstacleActive;

            foreach (LevelEntity entity in entities)
            {
                entity.SetObstacleActive(isObstacleActive);
            }

            region.NotifyEntityObstacleChange(player, entities, isObstacleActive);

            ListPool<LevelEntity>.Put(entities);
        }
    }
}
